﻿
@{
    ViewBag.Title = "病案收费大类";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style>
    body {
        background: #DFC2F2;
        background-image: linear-gradient( 135deg, #d5b1f8 10%, #a49cf2 100%);
        background-attachment: fixed;
        background-size: cover;
        /*color:#3dd73c*/
    }
</style>

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_delete()"><i class="fa fa-pencil-square-o"></i>删除</a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="大类编号/大类名称" style="width: 180px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>


<script>
    $(function () {
        GridInit();
    });

    function GridInit() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/RecordManage/MrFee/GetPagintionList",
            autowidth: true,
            height: $(window).height() - 118,
            colModel: [
                { label: "id1", name: "id1", hidden: true },
                { label: "id2", name: "id2", hidden: true },
                { label: "id3", name: "id3", hidden: true },
                { label: "一级大类编号", name: "code1", width: 180, align: 'left' },
                { label: "一级大类名称", name: "name1", width: 180, align: 'left' },
                { label: "二级大类编号", name: "code2", width: 180, align: 'left' },
                { label: "二级大类名称", name: "name2", width: 180, align: 'left' },
                { label: "三级大类编号", name: "code3", width: 180, align: 'left' },
                { label: "三级大类名称", name: "name3", width: 180, align: 'left' }
            ],
            sortname: "code1",
            rowNum: 13,
            pager: "#gridPager",
            viewrecords: true,
            ondblClickRow: function () {
                btn_edit();
            },
        });
        $("#btn_search").click(function () {
            $("#gridList").jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() }, page: 1
            }).trigger('reloadGrid');
        });
    }

    function btn_add() {
        window.$.modalOpen({
            id: "Form",
            title: "新增病案收费大类",
            url: "/RecordManage/MrFee/Form",
            width: "500px",
            height: "350px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                });
            }
        });
    }

    function btn_edit() {
        var id1 = $("#gridList").jqGridRowValue().id1;
        var id2 = $("#gridList").jqGridRowValue().id2;
        var id3 = $("#gridList").jqGridRowValue().id3;
        var keyValue = "";
        var index = 0;
        if (!!id3) {
            keyValue = id3;
            index = 3;
        } else if (!!id2) {
            keyValue = id2;
            index = 2;
        } else if (!!id1) {
            keyValue = id1;
            index = 1;
        }
        if (keyValue=="") {
            $.modalAlert("请选中一条信息", 'warning');
            return false;
        }
        $.modalOpen({
            id: "updateForm",
            title: "修改病案收费大类",
            url: "/RecordManage/MrFee/Form?keyValue=" + keyValue+"&index="+index,
            width: "500px",
            height: "350px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                });
            }
        });
    }

    function btn_delete() {
        window.$.modalConfirm("确定要删除吗？", function (flag) {
            if (!flag) {
                return false;
            }
            return true;
        });

        var id1 = $("#gridList").jqGridRowValue().id1;
        var id2 = $("#gridList").jqGridRowValue().id2;
        var id3 = $("#gridList").jqGridRowValue().id3;
        var keyValue = "";
        if (!!id3) {
            keyValue = id3;
        } else if (!!id2) {
            keyValue = id2;
        } else if (!!id1) {
            keyValue = id1;
        }
        if (keyValue == "") {
            $.modalAlert("请选中一条信息", 'warning');
            return false;
        }
        window.$.deleteForm({
            url: "/RecordManage/MrFee/DeleteData",
            param: { keyValue: keyValue },
            success: function () {
                $.modalMsg("删除成功", "success");
                $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                $("#btn_search").trigger("click");
            }
        });
        return true;
    }
</script>

